<template>
    <div>
        <hd-tab :tabs="tabs"></hd-tab>
        <el-card class="box-card">
            <el-form ref="form" :model="form" label-width="80px">
                <el-form-item label="幻灯片名称">
                    <el-input v-model="form.title"></el-input>

                </el-form-item>
                <el-form-item label="上传图片">
                    <hd-image v-model="form.url"></hd-image>
                    <hd-alert :alert="{type:'success'}">图片格式为1526px*320px</hd-alert>
                </el-form-item>
                <el-form-item label="是否推荐">
                    <el-radio-group v-model="form.recommend">
                        <el-radio :label=1>是</el-radio>
                        <el-radio :label=0>否</el-radio>
                    </el-radio-group>
                </el-form-item>
            </el-form>

            <el-button type="success" @click="onSubmit">保存提交</el-button>
        </el-card>
    </div>
</template>

<script>
import tabs from './tabs'

const form = {}
export default {

    props: ['id'],
    data() {
        return {
            tabs,
            form: {},
        }
    },

    async created() {
        if (this.id) {
            this.form = await this.axios.get(`admin/sidershow/${this.id}`)
        }
    },
    methods: {
        async onSubmit() {
            const url = this.id ? `admin/sidershow/${this.id}` : `admin/sidershow`;
            await this.axios[this.id ? 'put' : 'post'](url, this.form)
            this.$router.push({name: 'admin.sidershow.index'})
        }
    }
}
</script>

<style scoped>

</style>
